package com.dragon.client.controller.website;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.website.IDisplayExampleService;
import com.dragon.repository.domain.dto.DisplayExampleDTO;
import com.dragon.repository.domain.vo.DisplayExampleVO;
import com.dragon.repository.entity.DisplayExample;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 案例展示 前端控制器
 * </p>
 *
 * @author sy
 * @since 2024-03-01
 */
@RestController
@RequestMapping("displayExample")
@Api(tags = "案例展示")
public class DisplayExampleController {

    @Autowired
    IDisplayExampleService service;

    @GetMapping("list")
    @ApiOperation(value = "案例列表")
    public ResponseData<List<DisplayExampleDTO>> exampleList(){
        List<DisplayExample> displayExampleList = service.exampleList();
        return ResponseData.success(DisplayExampleDTO.convertList(displayExampleList));
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData displayExampleAdd(@RequestBody @Validated(Insert.class)DisplayExampleVO vo){
        service.displayExampleAdd(DisplayExampleVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改")
    public ResponseData displayExampleUpdate(@RequestBody @Validated(Update.class)DisplayExampleVO vo){
        service.displayExampleUpdate(DisplayExampleVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除")
    public ResponseData displayExampleDeleted(
            @ApiParam(name = "id", value = "id", required = true, type = "int")
            @RequestParam Integer id
    ){
        service.displayExampleDeleted(id);
        return ResponseData.success();
    }

}
